added samples
[windows-sources.git] / sdk / samples / all in on code / Visual Studio 2008 / VBWinFormBindingNestedProperties / MainForm.vb
blob9987ef1ffda5132a8733835a9c9254d5d008617d
1 '*********************************** Module Header **************************************\
2 ' Module Name: MainForm.vb
3 ' Project: VBWinFormBindToNestedProperties
4 ' Copyright (c) Microsoft Corporation.
5 '
6 ' The sample demonstrates how to bind a DataGridView column to a nested property
7 ' in the data source.
8 '
9 ' This source is subject to the Microsoft Public License.
10 ' See http://www.microsoft.com/opensource/licenses.mspx#Ms-PL.
11 ' All other rights reserved.
13 ' THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
14 ' EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
15 ' WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
16 '*****************************************************************************************/
18 Imports System.ComponentModel
20 Public Class MainForm
21 Inherits Form
23 Private mylist As New BindingList(Of Person)
25 Public Sub New()
26 MyBase.New()
27 InitializeComponent()
28 End Sub
30 Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
31 ' bind the DataGridView to the list
32 Me.DataGridView1.AutoGenerateColumns = False
33 Me.DataGridView1.DataSource = mylist
35 Me.DataGridView1.Columns.Add("ID", "ID")
36 Me.DataGridView1.Columns.Add("Name", "Name")
37 Me.DataGridView1.Columns.Add("CityName", "City Name")
38 Me.DataGridView1.Columns.Add("PostCode", "Post Code")
40 CType(Me.DataGridView1.Columns("ID"), DataGridViewTextBoxColumn).DataPropertyName = "ID"
41 CType(Me.DataGridView1.Columns("Name"), DataGridViewTextBoxColumn).DataPropertyName = "Name"
42 CType(Me.DataGridView1.Columns("CityName"), DataGridViewTextBoxColumn).DataPropertyName = "HomeAddr_CityName"
43 CType(Me.DataGridView1.Columns("PostCode"), DataGridViewTextBoxColumn).DataPropertyName = "HomeAddr_PostCode"
44 End Sub
46 Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
47 ' add objects of type Person to a list
48 Dim p As New Person
49 p.ID = "1"
50 p.Name = "aa"
52 Dim addr As New Address
53 addr.Cityname = "city name1"
54 addr.Postcode = "post code1"
55 p.HomeAddr = addr
57 mylist.Add(p)
59 p = New Person
60 p.ID = "2"
61 p.Name = "bb"
63 addr = New Address
64 addr.Cityname = "city name2"
65 addr.Postcode = "post code2"
66 p.HomeAddr = addr
68 mylist.Add(p)
69 End Sub
70 End Class